<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
    protected $primaryKey = 'id';
    protected $guarded = [];
    protected $table = 'users';

    public function fans(){
        return $this->belongsToMany('App\Models\User','concerns','star_id','fan_id');
    }

    public function stars(){
        return $this->belongsToMany('App\Models\User','concerns','fan_id','star_id');
    }

    public function posts(){
        return $this->hasMany('App\Models\Post','user_id','id')->orderBy('created_at','desc');
    }

    public function concerned(){
        return $this->hasOne('App\Models\Concern','star_id','id')->where('fan_id',\Auth::id())->first();
    }
    public function notices(){
        return $this->belongsToMany('App\Models\Notice','user_notice','user_id','notice_id');
    }
}
